Given two
positive integers a and b. Check if a is
divisible by b without a remainder.
Input. Two positive integers a and b (1
≤ a, b ≤ 109).
Output. If a is not divisible by b, print two numbers in
a single line: the quotient and the remainder of a divided
by b. If a is divisible by b, print
the string “Divisible”.
Sample input 1 |
Sample output 1 |
12 5 |
2 2 |
|
|
Sample input 2 |
Sample output 2 |
15 3 |
Divisible |
conditional
statement
Algorithm
analysis
A number a
is divisible by b if the remainder of dividing a by b
equals 0. To solve the problem, use a conditional operator.
Algorithm implementation
Read the input data.
scanf("%d %d",&a,&b);
Check
whether a is divisible by b. Depending on the result, print the corresponding answer.
if (a % b != 0)
printf("%d %d\n",a/b,a%b);
else
printf("Divisible\n");
Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int a = con.nextInt();
int b = con.nextInt();
if (a % b != 0)
System.out.print(a/b + " " + a%b);
else
System.out.println("Divisible");
con.close();
}
}
Python implementation
Read the input data.
a, b = map(int,input().split())
Check
whether a is divisible by b. Depending on the result, print the corresponding answer.
if a % b != 0:
print(a // b, a % b);
else:
print("Divisible");